#define _CRT_SECURE_NO_WARNINGS 1
#include"queue.h"

void test() {
	Queue queue;
	QueueInit(&queue);
	QueuePush(&queue, 1);
	QueuePush(&queue, 2);
	QueuePush(&queue, 3);
	QueuePush(&queue, 4);
	QueuePush(&queue, 5);
	/*QueuePop(&queue);
	QueuePop(&queue);*/
	/*QueuePop(&queue);
	QueuePop(&queue);
	QueuePop(&queue);*/
	/*QueuePop(&queue);*/
	/*while ((&queue)->front) {
		QueueFront(&queue);
		QueuePop(&queue);
	}
	printf("\n");*/
	/*QueueBack(&queue);*/
	/*int ret = QueueSize(&queue);*/
	/*int ret = QueueEmpty(&queue);*/
	QueueDestroy(&queue);
}


typedef struct {
	Queue queue1;
	Queue queue2;
} MyStack;

MyStack* myStackCreate() {
	MyStack* stack = (MyStack*)malloc(sizeof(MyStack));
	QueueInit(&stack->queue1);
	QueueInit(&stack->queue2);
	return stack;
}

void myStackPush(MyStack* obj, int x) {
	if (!QueueEmpty(&obj->queue1)) {
		QueuePush(&obj->queue1, x);
	}
	else QueuePush(&obj->queue2, x);
}

int myStackPop(MyStack* obj) {
	Queue* empty = &obj->queue1;
	Queue* noempty = &obj->queue2;
	if (!QueueEmpty(&obj->queue1)) {
		 empty = &obj->queue2;
		 noempty = &obj->queue1;
	}
	while (QueueSize(noempty) > 1) {
		QueuePush(empty, QueuePop(noempty));
	}
	return QueuePop(noempty);

}

int myStackTop(MyStack* obj) {
	if (!QueueEmpty(&obj->queue1)) return QueueBack(&obj->queue1);
	else return QueueBack(&obj->queue2);
}

bool myStackEmpty(MyStack* obj) {
	return (QueueEmpty(&obj->queue1) && QueueEmpty(&obj->queue2));
}

void myStackFree(MyStack* obj) {
	QueueDestroy(&obj->queue1);
	QueueDestroy(&obj->queue2);
	free(obj);
	obj = NULL;
}






int main() {
	MyStack* obj=myStackCreate();
	myStackPush(obj, 1);
	myStackPush(obj, 2);
	int top = myStackTop(obj);
	int pop = myStackPop(obj);
	pop = myStackPop(obj);
	printf("%d ", myStackEmpty(obj));
	return 0;
}